﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace MapleLeaf.Client{

    public class VisibilityConverter : IValueConverter {

        public VisibilityConverter(bool invert = false) : base() {
 
            Invert = invert;
        }


        public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
            bool flag = false;
            if (value is string text) {
                if (text != null && text.Length > 0) {
                    flag = true;
                }
            } else if (value is bool boolean && boolean) {
                flag = true;
            }
            object result = Invert ? flag ? Visibility.Collapsed : Visibility.Visible : (object)(flag ? Visibility.Visible : Visibility.Collapsed);
            return result;
        }


        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
            throw new NotImplementedException();
        }

        static VisibilityConverter() {
            Default = new VisibilityConverter(false);
            DefaultInvert = new VisibilityConverter(true);
        }


        public static readonly VisibilityConverter Default;


        public static readonly VisibilityConverter DefaultInvert;


        private readonly bool Invert;
    }
}
